package com.zycfc.zsf.boot.mq.rabbitmq.autoconfigure;

import org.springframework.boot.context.properties.*;
import org.springframework.boot.autoconfigure.*;
import com.zycfc.zsf.boot.serializer.autoconfigure.*;
import org.springframework.beans.factory.annotation.*;
import com.zycfc.zsf.boot.mq.rabbitmq.producer.*;
import org.springframework.context.annotation.*;
import com.zycfc.zsf.boot.mq.rabbitmq.config.*;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.boot.actuate.health.*;
import com.zycfc.zsf.boot.serializer.*;
import com.zycfc.zsf.boot.mq.rabbitmq.retry.*;
import org.slf4j.*;

@Configuration
@EnableConfigurationProperties({ RetryCacheProperties.class })
@ConditionalOnProperty({ "zsf.boot.rabbitmq.retry.enabled", "spring.rabbitmq.publisher-confirms" })
@AutoConfigureAfter({ ZsfRabbitMQConfiguration.class, SerializerAutoConfiguration.class })
public class ZsfRetryCacheConfiguration
{
    private static final Logger log;
    @Autowired
    private RetryCacheProperties retryCacheProperties;
    
    @Bean
    public RetryCache rabbitMQRetryCache(final SimpleMessageProducer simpleMessageProducer) {
        final RetryCache rabbitMQRetryCache = new RetryCache(this.retryCacheProperties);
        simpleMessageProducer.setRetryCache(rabbitMQRetryCache);
        ZsfRetryCacheConfiguration.log.debug("\u521d\u59cb\u5316Message\u7f13\u5b58");
        return rabbitMQRetryCache;
    }
    
    @Bean
    @ConditionalOnClass({ HealthIndicator.class })
    public RabbitMQRetryHealthIndicator rabbitMQRetryHealthIndicator(final RetryCache rabbitMQRetryCache) {
        ZsfRetryCacheConfiguration.log.debug("\u914d\u7f6eZsfRetryServerHealthIndicator");
        return new RabbitMQRetryHealthIndicator(rabbitMQRetryCache, this.retryCacheProperties);
    }
    
    @Bean
    public RetryThread rabbitMQRetryThread(final SimpleMessageProducer simpleMessageProducer, final RetryCache rabbitMQRetryCache) {
        final RetryThread retryThread = new RetryThread(rabbitMQRetryCache, simpleMessageProducer, this.retryCacheProperties);
        ZsfRetryCacheConfiguration.log.debug("\u914d\u7f6eRetryThread");
        return retryThread;
    }
    
    @Bean
    public PersistentThread rabbitMQRetryPersistentThread(final RetryCache rabbitMQRetryCache, final ISerializer serializer) {
        final PersistentThread persistentThread = new PersistentThread(rabbitMQRetryCache, serializer, this.retryCacheProperties);
        ZsfRetryCacheConfiguration.log.debug("\u914d\u7f6ePersistentThread");
        return persistentThread;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)ZsfRetryCacheConfiguration.class);
    }
}
